//package com.xiguaji.tiktok.task.blogger.repository;
//
//import com.gugee.tiktok.common.model.mysql.Blogger;
//import com.gugee.tiktok.common.model.mysql.BloggerMain;
//import com.xiguaji.boot.toolkit.DateTimeUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Lazy;
//import org.springframework.jdbc.core.BatchPreparedStatementSetter;
//import org.springframework.jdbc.core.BeanPropertyRowMapper;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.jdbc.core.RowMapper;
//import org.springframework.util.StringUtils;
//
//import java.sql.PreparedStatement;
//import java.sql.SQLException;
//import java.util.List;
//import java.util.stream.Collectors;
//
//public class BloggerMainExtRepositoryImpl implements BloggerMainExtRepository {
//    @Autowired
//    JdbcTemplate jdbcTemplate;
//
//    @Autowired
//    @Lazy
//    BloggerMainRepository bloggerMainRepository;
//
//    @Override
//    public void batchInsert(List<Blogger> bloggerList, String who) {
//        long seconds = DateTimeUtils.currentTimeSecond();
//
//        jdbcTemplate.batchUpdate(
//                "INSERT INTO `blogger_main` " +
//                        "(`id`, `o_uid`, `o_avatar300`, `o_avatar_medium`, `o_follower_count`, `o_district`, `o_signature`, `o_mplatform_followers_count`, `o_cover_url`, `o_is_star`, `o_avg_views`, " +
//                        "`o_avg_likes`, `o_avg_reviews`, `o_avg_share`, `o_following_count`, `o_total_favorited`, `o_dongtai_count`, `o_avatar168`, `o_gender`, `o_share_info`, `o_avatar_larger`," +
//                        "`o_birthday`, `o_country`, `o_city`, `o_is_activity_user`, `o_avatar_thumb`, `o_province`, `o_aweme_count`, `o_location`, `o_sec_uid`, `o_nickname`, `o_room_id`, `o_region`," +
//                        "`o_video_icon`, `o_unique_id`, `o_constellation`, `o_enterprise_verify_reason`, `o_with_fusion_shop_entry`, `blogger_type`, `blogger_type_audit_status`, `score`,`create_time`, `update_time`, `create_by`, `update_by`)" +
//                        " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
//                , new BatchPreparedStatementSetter() {
//                    @Override
//                    public void setValues(PreparedStatement preparedStatement, int i) throws SQLException {
//                        Blogger blogger = bloggerList.get(i);
//                        preparedStatement.setLong(1, 0);
//                        preparedStatement.setLong(2, blogger.getOUid());
//                        preparedStatement.setString(3, blogger.getOAvatar300());
//                        preparedStatement.setString(4, blogger.getOAvatarMedium());
//                        preparedStatement.setInt(5, blogger.getOFollowerCount());
//                        preparedStatement.setString(6, blogger.getODistrict());
//                        preparedStatement.setString(7, blogger.getOSignature());
//                        preparedStatement.setInt(8, blogger.getOMplatformFollowersCount());
//                        preparedStatement.setString(9, blogger.getOCoverUrl());
//                        preparedStatement.setBoolean(10, blogger.isOIsStar());
//                        preparedStatement.setLong(11, blogger.getOAvgViews());
//                        preparedStatement.setLong(12, blogger.getOAvgLikes());
//                        preparedStatement.setLong(13, blogger.getOAvgReviews());
//                        preparedStatement.setLong(14, blogger.getOAvgShare());
//                        preparedStatement.setInt(15, blogger.getOFollowingCount());
//                        preparedStatement.setLong(16, blogger.getOTotalFavorited());
//                        preparedStatement.setInt(17, blogger.getODongtaiCount());
//                        preparedStatement.setString(18, blogger.getOAvatar168());
//                        preparedStatement.setInt(19, blogger.getOGender());
//                        preparedStatement.setString(20, blogger.getOShareInfo());
//                        preparedStatement.setString(21, blogger.getOAvatarLarger());
//                        preparedStatement.setString(22, blogger.getOBirthday());
//                        preparedStatement.setString(23, blogger.getOCountry());
//                        preparedStatement.setString(24, blogger.getOCity());
//                        preparedStatement.setBoolean(25, blogger.isOIsActivityUser());
//                        preparedStatement.setString(26, blogger.getOAvatarThumb());
//                        preparedStatement.setString(27, blogger.getOProvince());
//                        preparedStatement.setInt(28, blogger.getOAwemeCount());
//                        preparedStatement.setString(29, blogger.getOLocation());
//                        preparedStatement.setString(30, blogger.getOSecUid());
//                        preparedStatement.setString(31, blogger.getONickname());
//                        preparedStatement.setLong(32, blogger.getORoomId());
//                        preparedStatement.setString(33, blogger.getORegion());
//                        preparedStatement.setString(34, blogger.getOVideoIcon());
//                        preparedStatement.setString(35, blogger.getOUniqueId());
//                        preparedStatement.setLong(36, blogger.getOConstellation());
//                        preparedStatement.setString(37, blogger.getOEnterpriseVerifyReason());
//                        preparedStatement.setBoolean(38, blogger.isOWithFusionShopEntry());
//                        preparedStatement.setString(39, "");
//                        preparedStatement.setInt(40, 0);
//                        preparedStatement.setInt(41, 0);
//                        preparedStatement.setLong(42, seconds);
//                        preparedStatement.setLong(43, seconds);
//                        preparedStatement.setString(44, who);
//                        preparedStatement.setString(45, who);
//                    }
//
//                    @Override
//                    public int getBatchSize() {
//                        return bloggerList.size();
//                    }
//                });
//    }
//
//    @Override
//    public List<Long> getNotExistBloggerIds(List<Long> uids) {
//        return uids.stream().filter(uid -> !bloggerMainRepository.existsByoUid(uid)).collect(Collectors.toList());
//    }
//
//
//    @Override
//    public List<BloggerMain> getBloggersByBloggerTypeSortDesc(String bloggerType, int limit){
//        StringBuffer sql = new StringBuffer("select * from blogger_main ");
//
//        if(!StringUtils.isEmpty(bloggerType)){
//            sql.append(" where blogger_type = ").append("'").append(bloggerType).append("'");
//        }
//        sql.append(" order by score desc limit 0,").append(limit);
//        RowMapper<BloggerMain> rowMapper = BeanPropertyRowMapper.newInstance(BloggerMain.class);
//        return jdbcTemplate.query(sql.toString(), rowMapper);
//    }
//
//    public void update(BloggerMain blogger, String operator) {
//        var optionalBlogger = bloggerMainRepository.findByoUid(blogger.getOUid());
//
//        var origin = optionalBlogger.get();
//        blogger.setId(origin.getId());
//        blogger.setCreateTime(origin.getCreateTime());
//        blogger.setCreateBy(origin.getCreateBy());
//        blogger.setUpdateBy(operator);
//        blogger.setBloggerType(origin.getBloggerType());
//        blogger.setBloggerTypeAuditStatus(origin.getBloggerTypeAuditStatus());
//        bloggerMainRepository.save(blogger);
//    }
//
//}
